<template>
  <div class="app-container">
    <div class="searchBox">
      <el-form :inline="true" :model="queryParams" ref="queryParams">
        <el-form-item label="表名称">
          <el-input
            v-model="queryParams.tableName"
            name="code"
            placeholder="请输入表名称"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="表描述">
          <el-input
            v-model="queryParams.tableComment"
            placeholder="请输入表描述"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery"
            >查询</el-button
          >
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="queryParams = {}"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <vxe-toolbar custom />
    <vxe-table
      ref="genImportTableRef"
      :data="tableData"
      @checkbox-change="checkboxChangeHandle"
      @checkbox-all="checkboxAllHandle"
      :loading="tableLoading"
      :highlight-current-row="true"
      :highlight-hover-row="true"
      :highlight-current-column="true"
      :highlight-hover-column="true"
    >
      <vxe-column type="checkbox" width="60" align="center" />
      <vxe-column field="tableName" title="表名称" show-overflow />
      <vxe-column field="tableComment" title="表描述" show-overflow />
      <vxe-column field="className" title="实体类" show-overflow />
      <vxe-column field="createTime" title="创建时间" show-overflow />
      <vxe-column field="updateTime" title="更新时间" show-overflow />
    </vxe-table>

    <vxe-pager
      v-if="total > 0"
      class="qm-table-el-pager"
      :current-page="queryParams.pageNum"
      :page-size="queryParams.pageSize"
      :total="total"
      :pageSizes="[5, 10, 20, 50, 100]"
      @page-change="handlePageChange"
    />
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "GenImport",
  components: {},
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tableName: undefined,
        tableComment: undefined,
      },
      tableData: [],
      total: 0,
      tableLoading: false,
    };
  },
  created() {
    this.loadGenTableList();
  },
  methods: {
    async handleQuery() {
      try {
        this.tableLoading = true;
        const res = await request({
          url: "/tool/gen/db/list",
          method: "get",
          params: this.queryParams,
        });
        this.tableData = res.list;
        this.total = res.total;
      } finally {
        this.tableLoading = false;
      }
    },
    loadGenTableList() {
      this.handleQuery();
    },
    handlePageChange({ currentPage, pageSize }) {
      this.queryParams.pageNum = currentPage;
      this.queryParams.pageSize = pageSize;
      this.handleQuery();
    },
    checkboxChangeHandle(v) {
      this.emitSelectRowsEvent(v.records);
    },
    checkboxAllHandle(v) {
      this.emitSelectRowsEvent(v.records);
    },
    emitSelectRowsEvent(records) {
      this.$emit("selectRowsEvent", records);
    },
  },
};
</script>

<style scoped lang="scss">
</style>

